package com.yjxxt.studentInfo;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.lib.db.DBWritable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 对应表结构
 *
 * CREATE TABLE `student_info`  (
 *   `id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
 *   `gender` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
 *   `video_grade` double(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
 *   `job_grade` double(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
 *   `exam_grade` double(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
 *   `total_grade` double(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
 *   PRIMARY KEY (`id`) USING BTREE
 * ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
 *
 */

public class StudentInfo implements Writable, DBWritable {

    private String id;
    private double video_grade;
    private double job_grade;
    private double exam_grade;
    private double total_grade;
    private String gender;

    public StudentInfo() {
    }

    public StudentInfo(String id, String gender , double video_grade, double job_grade ,double exam_grade , double total_grade) {
        this.id = id;
        this.gender = gender;
        this.video_grade = video_grade;
        this.job_grade = job_grade;
        this.exam_grade = exam_grade;
        this.total_grade = total_grade;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getgender() {
        return gender;
    }

    public void setgender(String gender) {
        this.gender = gender;
    }

    public double getVideo_grade() {
        return video_grade;
    }

    public void setVideo_grade(double grade) {
        this.video_grade = grade;
    }

    public double getJob_grade() {
        return video_grade;
    }

    public void setJob_grade(double grade) {
        this.job_grade = grade;
    }

    public double getExam_grade() {
        return video_grade;
    }

    public void setExam_grade(double grade) {
        this.exam_grade = grade;
    }

    public double getTotal_grade() {
        return video_grade;
    }

    public void setTotal_grade(double grade) {
        this.total_grade = grade;
    }

    @Override
    public String toString() {
        return "grade{" +
                "id='" + id + '\'' +
                ", gender='" + gender + '\'' +
                ", video_grade='" + video_grade + '\'' +
                ", job_grade='" + job_grade + '\'' +
                ", exam_grade='" + exam_grade + '\'' +
                ", total_grade='" + total_grade +
                '}';
    }


    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(this.id);
        dataOutput.writeUTF(this.gender);
        dataOutput.writeDouble(this.video_grade);
        dataOutput.writeDouble(this.job_grade);
        dataOutput.writeDouble(this.exam_grade);
        dataOutput.writeDouble(this.total_grade);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.id = dataInput.readUTF();
        this.gender = dataInput.readUTF();
        this.video_grade = dataInput.readDouble();
        this.job_grade = dataInput.readDouble();
        this.exam_grade = dataInput.readDouble();
        this.total_grade = dataInput.readDouble();
    }

    @Override
    public void write(PreparedStatement preparedStatement) throws SQLException {
        preparedStatement.setString(1, this.id);
        preparedStatement.setString(2, this.gender);
        preparedStatement.setDouble(3, this.video_grade);
        preparedStatement.setDouble(4, this.job_grade);
        preparedStatement.setDouble(5, this.exam_grade);
        preparedStatement.setDouble(6, this.total_grade);

    }

    @Override
    public void readFields(ResultSet resultSet) throws SQLException {
        this.id = resultSet.getString(1);
        this.gender = resultSet.getString(2);
        this.video_grade = resultSet.getDouble(3);
        this.job_grade = resultSet.getDouble(4);
        this.exam_grade = resultSet.getDouble(5);
        this.total_grade = resultSet.getDouble(6);
    }
}